﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using QMERP.Domain.Entities;

namespace QMERP.Infrastructure.EFCore.Mappings
{
    public class BulkOrderDetailMapping : IEntityTypeConfiguration<BulkOrderDetail>
    {
        public void Configure(EntityTypeBuilder<BulkOrderDetail> builder)
        {
            builder.Property(x => x.Diameter).IsRequired(false);
            builder.Property(x => x.Packet).IsRequired(false).HasMaxLength(500);

            builder.Property(x => x.BulkOrderId);
            builder.Property(x => x.SupplierId);
            builder.Property(x => x.WarehouseId);
            builder.Property(x => x.Contract_LensId);
            

            builder.HasOne(x => x.Contract_Lens)
               .WithMany(t => t.BulkOrderDetails)
               .HasForeignKey(m => m.Contract_LensId)
               .OnDelete(DeleteBehavior.NoAction);

            builder.HasIndex(x => x.Id);
            builder.HasIndex(x => x.BulkOrderId);
            builder.HasIndex(x => x.SupplierId);
            builder.HasIndex(x => x.WarehouseId);
            builder.HasIndex(x => x.Contract_LensId);
        }
    }
}
